<?php
session_start();
header("Content-Type:text/html;charset=utf-8");
include_once("conn.php");

$sql = "select * from category where name='".$_SESSION["current_user"]."'";
$result = mysql_query($sql);

while( $got = mysql_fetch_array($result) )
{
	$cid=$got["cid"];
	$cname=$got["cate_name"];
	echo "<div class='change_cate_style' id='".$cid."' style='float:left;'>";
	echo $got["cate_name"];
	echo "</div>";
	echo "<div class='controls'>";
		echo "<a href='#' class='add_link' onclick=show_add_link('add_cate".$got["cate_name"]."');return false;>";
		echo "<img src='/PNG/tiny_plus.png'>";
		echo "</a>";
		echo "<a href='#' class='divider' >";
		echo "</a>";
		echo "<a href='#' class='modify' onclick=cate_modify('".$got["cate_name"]."');return false;>";
		echo "<img src='/PNG/tiny_gear.png'>";
		echo "</a>";
	echo "</div>";
	/* 以下为增加分类中的增加网址模块 */
	echo "<div class='add_link_form'  id='add_cate".$got["cate_name"]."' style='padding-top:15px;padding-right:15px;padding-bottom-15px;padding-left:15px;display:none;'>";
	
	echo "<form action='index.php' method='post'>";
	
	echo "<input type='hidden' name='is_link_submit' value='yes' />";
	echo "<input type='hidden' name='cname' value='$cid' />";
	echo "<input type='text' name='link_name' placeholder='input your link name' />";
	echo "<input type='text' name='link_address' placeholder='create your new link' />";
	echo "<input type='submit' value='create link' />";
	
	echo "</form>";
	
	echo "</div>";
	
	/* 以上为增加分类中的网址模块 */
	
	/* 以下为修改分类信息模块*/
	echo "<div class='edit_cate_form' id='".$cname."' style='display:none';> ";
	echo "<form action='cate_process.php' method='post' > ";
	
	echo "<input type='text' class='cate_style' id='edit_cate_name' name='edit_cate_name' value='".$got["cate_name"]."' />";
	echo "&nbsp&nbsp&nbsp";
	echo "<input type='hidden' name='delcate_action' id='delcate_action' value='".$got["cate_name"]."' /> ";
	echo "<input type='hidden' name='cid2' id='cid2' value='".$cid."' />" ;
	echo "&nbsp&nbsp";
	echo "<input type='button' class='save_cate_style' name='save_cate' id='save_cate' value='save' onclick=\"change_cate('".$cname."',".$cid.");return false;\" />";
	echo "<input type='submit' name='del_cate' id='del_cate' value='delete'/>";


	echo "</form>";
	echo "</div>";

	/*  以上为修改分类信息模块*/
	

	$got_catename=$got["cate_name"];
	echo "<div class='link'>";
	$sql2="select category.cate_name,link.lid,webname,webaddress from category,cate_link,link where category.cid=cate_link.cid && link.lid=cate_link.lid ";
	mysql_query("set names utf-8");
	$result2=mysql_query($sql2);
	if($result2)
	{
		while($got_cate=mysql_fetch_array($result2))
		{
			if($got_cate["cate_name"]==$got_catename)
			{
				echo "<div class='link_line'>";
					echo $got_cate["webname"];
					$temp_webname=$got_cate["webname"];
					echo "&nbsp";
					echo "&nbsp";
					echo $got_cate["webaddress"];
					//$temp_webaddress=$got_cate["webaddress"];
					//$temp_lid=$got_cate["lid"];
					//$lid=$got_cate["lid"];
					echo "<div class='controls'>";
						echo "<a href='#' onclick=show_edit_link('edit_link_".$got_cate["lid"]."');>";
							echo "<img src=/元素/image/tiny_gear.png >";
						echo "</a>";
					echo "</div>";
				echo "</div>";
				/*以下为编辑链接FORM*/
				echo "<div id='edit_link_".$got_cate["lid"]."' style='display:none;'>"; 
					echo "<form method='post' action='link_process.php' name='".$got_cate["webname"]."'>";
					echo "<input type='text' name='alias' value='$got_cate[webname]' />";
					echo "<input type='text' name='alias_name' value='$got_cate[webaddress]'/>";
					echo "<input type='hidden' name='save' value='save' />";
					echo "<input type='hidden' name='".$got_cate["lid"]."' value='".$got_cate["webname"]."' />";
					echo "<input type='hidden' name='real_webname' value='".$got_cate["webname"]."' /> ";
					echo "<input type='submit' name='save_link' value='save' />";
					echo "<input type='submit' name='del_link' value='delete' />";
					echo "</form>";
				echo "</div>";
				/*以上为编辑链接FORM*/

			}

		}
	}
	else
	{
		echo "链接数据库读取失败";
	}
	

	


	echo "</div>";
}



?>